package com.ohos.carbon.provider;

import com.ohos.carbon.ResourceTable;
import com.ohos.carbon.model.DemoDataBean;
import ohos.agp.components.*;
import ohos.agp.utils.Color;
import ohos.app.Context;

import java.util.List;

public class ComponentImageProvider extends RecyclerAdapter<ComponentImageProvider.ViewHolder> {

    private List<DemoDataBean> mList;
    private Context context;

    public ComponentImageProvider(List<DemoDataBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ComponentContainer componentContainer) {

        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_component_image_provider, componentContainer, false);
        return new ViewHolder(component);
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        ViewHolder viewHolder = holder;
        if (mList != null ) {
            if (position == 0 || position==5 || position==7 || position==11){
                viewHolder.on_text.setMultipleLine(true);
                viewHolder.on_text.setText(mList.get(position).getOn_text());
                viewHolder.on_text.setTextColor(Color.GRAY);
                viewHolder.on_text.setTextSize(38);
               viewHolder.left_img.setVisibility(Component.HIDE);
//                viewHolder.left_text.setVisibility(Component.HIDE);
//                viewHolder.right_text.setVisibility(Component.HIDE);
//                viewHolder.under_text.setVisibility(Component.HIDE);
                viewHolder.on_text.setPaddingLeft(130);
                viewHolder.on_text.setPaddingRight(110);
                viewHolder.on_text.setMarginTop(60);
            }
            viewHolder.left_img.setImageAndDecodeBounds(mList.get(position).getLeft_img());
            viewHolder.left_text.setText(mList.get(position).getLeft_text());
            viewHolder.on_text.setText(mList.get(position).getOn_text());
            viewHolder.under_text.setText(mList.get(position).getUnder_text());
            viewHolder.right_text.setText(mList.get(position).getRight_text());
            viewHolder.under_text.setTextColor(Color.GRAY);
        }

    }


    @Override
    public Object getItem(int position) {
        if (mList != null && position >= 0 && position < mList.size()) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int positon) {
        return positon;
    }
    class ViewHolder extends RecyclerAdapter.ViewHolder {

        private Image left_img;
        private Text left_text,on_text,under_text,right_text;

        public ViewHolder(Component itemComponent) {
            super(itemComponent);
            left_img = (Image) itemComponent.findComponentById(ResourceTable.Id_left_img);
            left_text = (Text) itemComponent.findComponentById(ResourceTable.Id_left_text);
            on_text = (Text) itemComponent.findComponentById(ResourceTable.Id_on_text);
            under_text = (Text) itemComponent.findComponentById(ResourceTable.Id_under_text);
            right_text = (Text) itemComponent.findComponentById(ResourceTable.Id_right_text);
        }
    }
}
